﻿using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp3SingleObjectBinding;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private readonly Person _person;
    public MainWindow()
    {
        InitializeComponent();
        _person = new Person("Bart", 10);
        DataContext = _person;
    }

    private void OnChange(object sender, RoutedEventArgs e)
    {
        _person.Age++;
    }
}

class Person : ObservableObject
{
    private int _age;
    public Person(string name, int age)
    {
        Name = name;
        Age = age;
    }
    public string Name { get; set; }
    public int Age
    {
        get { return _age; }
        set
        {
            if (_age != value)
            {
                _age = value;
                OnPropertyChanged(nameof(Age));
            }
        }
    }
}
//class Person : INotifyPropertyChanged
//{
//    private int _age;
//    public Person(string name, int age)
//    {
//        Name = name;
//        Age = age;
//    }
//    public string Name { get; set; }
//    public int Age
//    {
//        get { return _age; }
//        set
//        {
//            _age = value;
//            var pc = PropertyChanged;
//            if(pc != null)
//            {
//                pc(this, new PropertyChangedEventArgs(nameof(Age)));
//            }
//        }
//    }

//    public event PropertyChangedEventHandler? PropertyChanged;
//}
//record Person(string Name, int Age);
